﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DBSourceToolsLib.SysObjects
{
    public class SOList : IEnumerable<SysObject>//, IEnumerable<SOTable>
    {
        //private SortedList<string, SOQuery> m_Queries = new SortedList<string, SOQuery>();
        //private SortedList<string, SOTable> m_Tables = new SortedList<string, SOTable>();
        private SortedList<string, SysObject> m_SysObjectsList = new SortedList<string, SysObject>();

        #region IEnumerable<SysObject> Members

        public IEnumerator<SysObject> GetEnumerator()
        {
            foreach (SysObject oSysObject in m_SysObjectsList.Values)
            {
                yield return oSysObject;
            }
        }
        public IEnumerable<SOTable> Tables
        {
            get
            {
                foreach (SysObject oSysObject in m_SysObjectsList.Values)
                {
                    if (oSysObject.Type == SysObjectType.Table)
                    {
                        yield return (SOTable)oSysObject;
                    }
                }
            }
        }
        //public IEnumerator<SOTable> GetEnumerator()
        //{
        //    foreach (SysObject oSysObject in m_SysObjectsList.Values)
        //    {
        //        if (oSysObject.Type == SysObjectType.Table)
        //        {
        //            yield return (SOTable)oSysObject;
        //        }
        //    }

        //}
        //public IEnumerator<SOTable> Tables
        //{
        //    get
        //    {
        //        foreach (SysObject oSysObject in m_SysObjectsList.Values)
        //        {
        //            if (oSysObject.Type == SysObjectType.Table)
        //            {
        //                yield return (SOTable)oSysObject;
        //            }
        //        }
        //    }
        //}


        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new NotImplementedException();
        }

        public void Add(SysObject oSysObject) 
        {
            m_SysObjectsList.Add(oSysObject.QualifiedName, oSysObject);
            //switch (oSysObject.Type)
            //{
            //    case SysObjectType.Querie:
            //        m_Queries.Add(oSysObject.QualifiedName, (SOQuery)oSysObject);
            //        break;
            //    case SysObjectType.Table:

            //        m_Tables.Add(oSysObject.QualifiedName, (SOTable)oSysObject);
            //        break;
            //}
        }

        #endregion


        #region IEnumerable<SOTable> Members


        #endregion

        #region IEnumerable<SOTable> Members

        //IEnumerator<SOTable> IEnumerable<SOTable>.GetEnumerator()
        //{
        //    throw new NotImplementedException();
        //}

        #endregion
    }
}
